Test Failed
Push — master ( 9811b7...5b4ca1 )
by Chad
16:14 queued 01:44
created

$(document).ready   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nop 0
nc 1
1
/*
2
 * doctools.js
3
 * ~~~~~~~~~~~
4
 *
5
 * Sphinx JavaScript utilities for all documentation.
6
 *
7
 * :copyright: Copyright 2007-2015 by the Sphinx team, see AUTHORS.
8
 * :license: BSD, see LICENSE for details.
9
 *
10
 */
11
12
/**
13
 * select a different prefix for underscore
14
 */
15
$u = _.noConflict();
0 ignored issues
show
Bug introduced by
The variable $u seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.$u.
Loading history...
Bug introduced by
The variable _ seems to be never declared. If this is a global, consider adding a /** global: _ */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
16
17
/**
18
 * make the code below compatible with browsers without
19
 * an installed firebug like debugger
20
if (!window.console || !console.firebug) {
21
  var names = ["log", "debug", "info", "warn", "error", "assert", "dir",
22
    "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace",
23
    "profile", "profileEnd"];
24
  window.console = {};
25
  for (var i = 0; i < names.length; ++i)
26
    window.console[names[i]] = function() {};
27
}
28
 */
29
30
/**
31
 * small helper function to urldecode strings
32
 */
33
jQuery.urldecode = function(x) {
34
  return decodeURIComponent(x).replace(/\+/g, ' ');
35
};
36
37
/**
38
 * small helper function to urlencode strings
39
 */
40
jQuery.urlencode = encodeURIComponent;
0 ignored issues
show
Bug introduced by
The variable encodeURIComponent seems to be never declared. If this is a global, consider adding a /** global: encodeURIComponent */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
41
42
/**
43
 * This function returns the parsed url parameters of the
44
 * current request. Multiple values per key are supported,
45
 * it will always return arrays of strings for the value parts.
46
 */
47
jQuery.getQueryParameters = function(s) {
48
  if (typeof s == 'undefined')
49
    s = document.location.search;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
50
  var parts = s.substr(s.indexOf('?') + 1).split('&');
51
  var result = {};
52
  for (var i = 0; i < parts.length; i++) {
53
    var tmp = parts[i].split('=', 2);
54
    var key = jQuery.urldecode(tmp[0]);
55
    var value = jQuery.urldecode(tmp[1]);
56
    if (key in result)
57
      result[key].push(value);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
58
    else
59
      result[key] = [value];
60
  }
61
  return result;
62
};
63
64
/**
65
 * highlight a given string on a jquery object by wrapping it in
66
 * span elements with the given class name.
67
 */
68
jQuery.fn.highlightText = function(text, className) {
69
  function highlight(node) {
70
    if (node.nodeType == 3) {
71
      var val = node.nodeValue;
72
      var pos = val.toLowerCase().indexOf(text);
73
      if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) {
74
        var span = document.createElement("span");
75
        span.className = className;
76
        span.appendChild(document.createTextNode(val.substr(pos, text.length)));
77
        node.parentNode.insertBefore(span, node.parentNode.insertBefore(
78
          document.createTextNode(val.substr(pos + text.length)),
79
          node.nextSibling));
80
        node.nodeValue = val.substr(0, pos);
81
      }
82
    }
83
    else if (!jQuery(node).is("button, select, textarea")) {
84
      jQuery.each(node.childNodes, function() {
85
        highlight(this);
86
      });
87
    }
88
  }
89
  return this.each(function() {
90
    highlight(this);
91
  });
92
};
93
94
/*
95
 * backward compatibility for jQuery.browser
96
 * This will be supported until firefox bug is fixed.
97
 */
98
if (!jQuery.browser) {
99
  jQuery.uaMatch = function(ua) {
100
    ua = ua.toLowerCase();
101
102
    var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
103
      /(webkit)[ \/]([\w.]+)/.exec(ua) ||
104
      /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
105
      /(msie) ([\w.]+)/.exec(ua) ||
106
      ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
107
      [];
108
109
    return {
110
      browser: match[ 1 ] || "",
111
      version: match[ 2 ] || "0"
112
    };
113
  };
114
  jQuery.browser = {};
115
  jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true;
0 ignored issues
show
Bug introduced by
The variable navigator seems to be never declared. If this is a global, consider adding a /** global: navigator */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
116
}
117
118
/**
119
 * Small JavaScript module for the documentation.
120
 */
121
var Documentation = {
122
123
  init : function() {
124
    this.fixFirefoxAnchorBug();
125
    this.highlightSearchWords();
126
    this.initIndexTable();
127
  },
128
129
  /**
130
   * i18n support
131
   */
132
  TRANSLATIONS : {},
133
  PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; },
134
  LOCALE : 'unknown',
135
136
  // gettext and ngettext don't access this so that the functions
137
  // can safely bound to a different name (_ = Documentation.gettext)
138
  gettext : function(string) {
139
    var translated = Documentation.TRANSLATIONS[string];
140
    if (typeof translated == 'undefined')
141
      return string;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
142
    return (typeof translated == 'string') ? translated : translated[0];
143
  },
144
145
  ngettext : function(singular, plural, n) {
146
    var translated = Documentation.TRANSLATIONS[singular];
147
    if (typeof translated == 'undefined')
148
      return (n == 1) ? singular : plural;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
149
    return translated[Documentation.PLURALEXPR(n)];
150
  },
151
152
  addTranslations : function(catalog) {
153
    for (var key in catalog.messages)
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
154
      this.TRANSLATIONS[key] = catalog.messages[key];
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
155
    this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')');
0 ignored issues
show
Performance Best Practice introduced by
Using new Function() to create a function is slow and difficult to debug. Such functions do not create a closure. Consider using another way to define your function.
Loading history...
156
    this.LOCALE = catalog.locale;
157
  },
158
159
  /**
160
   * add context elements like header anchor links
161
   */
162
  addContextElements : function() {
163
    $('div[id] > :header:first').each(function() {
164
      $('<a class="headerlink">\u00B6</a>').
165
      attr('href', '#' + this.id).
166
      attr('title', _('Permalink to this headline')).
167
      appendTo(this);
168
    });
169
    $('dt[id]').each(function() {
170
      $('<a class="headerlink">\u00B6</a>').
171
      attr('href', '#' + this.id).
172
      attr('title', _('Permalink to this definition')).
173
      appendTo(this);
174
    });
175
  },
176
177
  /**
178
   * workaround a firefox stupidity
179
   * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075
180
   */
181
  fixFirefoxAnchorBug : function() {
182
    if (document.location.hash)
183
      window.setTimeout(function() {
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
184
        document.location.href += '';
185
      }, 10);
186
  },
187
188
  /**
189
   * highlight the search words provided in the url in the text
190
   */
191
  highlightSearchWords : function() {
192
    var params = $.getQueryParameters();
193
    var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : [];
194
    if (terms.length) {
195
      var body = $('div.body');
196
      if (!body.length) {
197
        body = $('body');
198
      }
199
      window.setTimeout(function() {
200
        $.each(terms, function() {
201
          body.highlightText(this.toLowerCase(), 'highlighted');
202
        });
203
      }, 10);
204
      $('<p class="highlight-link"><a href="javascript:Documentation.' +
205
        'hideSearchWords()">' + _('Hide Search Matches') + '</a></p>')
206
          .appendTo($('#searchbox'));
207
    }
208
  },
209
210
  /**
211
   * init the domain index toggle buttons
212
   */
213
  initIndexTable : function() {
214
    var togglers = $('img.toggler').click(function() {
215
      var src = $(this).attr('src');
216
      var idnum = $(this).attr('id').substr(7);
217
      $('tr.cg-' + idnum).toggle();
218
      if (src.substr(-9) == 'minus.png')
219
        $(this).attr('src', src.substr(0, src.length-9) + 'plus.png');
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
220
      else
221
        $(this).attr('src', src.substr(0, src.length-8) + 'minus.png');
222
    }).css('display', '');
223
    if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) {
0 ignored issues
show
Bug introduced by
The variable DOCUMENTATION_OPTIONS seems to be never declared. If this is a global, consider adding a /** global: DOCUMENTATION_OPTIONS */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
224
        togglers.click();
225
    }
226
  },
227
228
  /**
229
   * helper function to hide the search marks again
230
   */
231
  hideSearchWords : function() {
232
    $('#searchbox .highlight-link').fadeOut(300);
233
    $('span.highlighted').removeClass('highlighted');
234
  },
235
236
  /**
237
   * make the url absolute
238
   */
239
  makeURL : function(relativeURL) {
240
    return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL;
0 ignored issues
show
Bug introduced by
The variable DOCUMENTATION_OPTIONS seems to be never declared. If this is a global, consider adding a /** global: DOCUMENTATION_OPTIONS */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
241
  },
242
243
  /**
244
   * get the current relative url
245
   */
246
  getCurrentURL : function() {
247
    var path = document.location.pathname;
248
    var parts = path.split(/\//);
249
    $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() {
0 ignored issues
show
Bug introduced by
The variable DOCUMENTATION_OPTIONS seems to be never declared. If this is a global, consider adding a /** global: DOCUMENTATION_OPTIONS */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
250
      if (this == '..')
251
        parts.pop();
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
252
    });
253
    var url = parts.join('/');
254
    return path.substring(url.lastIndexOf('/') + 1, path.length - 1);
255
  }
256
};
257
258
// quick alias for translations
259
_ = Documentation.gettext;
0 ignored issues
show
Bug introduced by
The variable _ seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window._.
Loading history...
260
261
$(document).ready(function() {
262
  Documentation.init();
263
});
264